package com.sunshine.lnuplus.viewModel

import android.app.Application
import android.content.Context
import com.sunshine.lnuplus.base.BaseViewModel
import com.sunshine.lnuplus.model.InitData
import com.sunshine.lnuplus.model.room.TimetableRepository

class LoginViewModel(application: Application) : BaseViewModel(application){

    val repository = TimetableRepository(application)
    private val appSetting = application.getSharedPreferences("com.sunshine.lnuplus_preferences", Context.MODE_PRIVATE)
    private val appSettingEdit = appSetting.edit()

    fun insertUser(user: String){
        appSettingEdit.putString("user_no", user)
        appSettingEdit.apply()
    }

    fun insertPassword(pw: String){
        appSettingEdit.putString("pw", pw)
        appSettingEdit.apply()
    }

    fun setMaxCount(count: Int){
        if(count > 5){
            appSettingEdit.putInt("height", 200)
            appSettingEdit.putInt("widget_height", 150)
            InitData.lessonStyle.height = 200
        } else {
            appSettingEdit.putInt("height", 400)
            appSettingEdit.putInt("widget_height", 200)
            InitData.lessonStyle.height = 400
        }
        appSettingEdit.putInt("every_day_count", count)
        InitData.lessonStyle.count = count
        appSettingEdit.apply()
    }

    fun setLessonTime(time: String){
        appSettingEdit.putString("lesson_time", time)
        appSettingEdit.apply()
    }

    fun getUser(): String? {
        return appSetting.getString("user_no", "")
    }

    fun getPassword(): String? {
        return appSetting.getString("pw", "")
    }
}